package com.hzyl.famousreader.viewmodel;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.ViewModel;
import com.hzyl.famousreader.repository.cache.AdBannerCache;
import com.hzyl.famousreader.repository.cache.AdCache;
import com.hzyl.famousreader.repository.persistence.AppDataBase;
import com.hzyl.famousreader.repository.persistence.dao.AdDao;
import com.hzyl.famousreader.repository.persistence.entity.Ad;
import com.hzyl.famousreader.repository.webservice.RetrofitClient;
import com.hzyl.famousreader.repository.webservice.api.AdService;
import com.hzyl.famousreader.repository.webservice.cache.Resource;
import com.hzyl.famousreader.repository.webservice.model.PageWrapper;

import java.util.List;

public class AdViewModel extends ViewModel {

  private AdService adService;

  private AdDao adDao;

  private AdBannerCache adBannerCache;

  private AdCache adCache;

  public AdViewModel() {
    adDao = AppDataBase.getInstance().adDao();
    adService = RetrofitClient.getInstance().create(AdService.class);
    adBannerCache = new AdBannerCache();
    adCache = new AdCache();
  }

  /**
   * 书城板块广告列表
   * @return
   */
  public LiveData<Resource<List<Ad>>> adBanners() {
    return adBannerCache.getAsLiveData();
  }

  /**
   * 发现板块广告列表
   * @return
   */
  public LiveData<Resource<PageWrapper<Ad>>> adDiscovery() {
    return adCache.getAsLiveData();
  }
}
